package benny_driving_ser.action;

import java.io.IOException;
import java.io.PrintWriter;

import cn.jpush.api.JPushClient;

import benny_driving_ser.util.JpushUtil;

public class JpushAction extends BaseAction{
	
	private String username;
	private PrintWriter out;
	
	
	public String jpushForSingle(){
		
		try{
			request.setCharacterEncoding("utf-8");
			response.setCharacterEncoding("utf-8");
			out = response.getWriter();
			int state = JpushUtil.JpushForSingle(username);
			if(state==0){
				out.print(state);
				out.flush();
				out.close();
				return "success";
			}else{
				
				out.print(state);
				out.flush();
				out.close();
				return "fail";
			}
			
		}catch(IOException e){
			e.printStackTrace();
		}
		return "fail";
	}
	
	
	public String jpushForAll(){
		
		try{
			request.setCharacterEncoding("utf-8");
			response.setCharacterEncoding("utf-8");
			out = response.getWriter();
			int state = JpushUtil.JpushForAll();
			if(state==0){
				out.print(state);
				out.flush();
				out.close();
				return "success";
			}else{
				
				out.print(state);
				out.flush();
				out.close();
				return "fail";
			}
			
		}catch(IOException e){
			e.printStackTrace();
		}
		return "fail";
	}
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public PrintWriter getOut() {
		return out;
	}
	public void setOut(PrintWriter out) {
		this.out = out;
	}
}
